package reit.ass3;


/**
 * The Class Location.
 */
class Location implements LocatableInterface {

	/** The x. */
	private Double x;

	/** The y. */
	private Double y;

	/**
	 * Instantiates a new location.
	 */
	public Location() {
		x = null;
		y = null;
	}

	/**
	 * Gets the x.
	 *
	 * @return the x
	 */
	public Double getX() {
		return new Double(x);
	}

	/**
	 * Gets the y.
	 *
	 * @return the y
	 */
	public Double getY() { 
		return new Double(y);
	}

	/**
	 * Instantiates a new location.
	 *
	 * @param x2 the x2
	 * @param y2 the y2
	 */
	public Location(final Double x2, final Double y2) {
		this.x = new Double(x2);
		this.y = new Double(y2);
	}


	/**
	 * Instantiates a new location.
	 *
	 * @param loc the loc
	 */
	public Location(final Location loc) {
		this.x = loc.getX();
		this.y= loc.getY();
	}

	/* (non-Javadoc)
	 * @see ass3.LocatableInterface#getLocation()
	 */
	@Override
	public Location getLocation() {

		return new Location(new Double(x),new Double(y));
	}

	/* (non-Javadoc)
	 * @see ass3.LocatableInterface#getDistance(ass3.Location)
	 */
	@Override
	public Double getDistance(final Location loc) {
		return Math.sqrt((this.x-loc.getX())*(this.x-loc.getX()) + (this.y-loc.getY())*(this.y-loc.getY()));
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object other){
		if (other instanceof Location){
			if (((Location) other).getX().floatValue() == this.getX().floatValue() && ((Location) other).getY().floatValue() == this.getY().floatValue())
				return true;
		}

		return false;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString(){
		StringBuilder s = new StringBuilder();
		s.append(x);
		s.append(',');
		s.append(y);
		return s.toString();

	}
}
